package com.jiaobuchong.beanstalkd;

import com.dinstone.beanstalkc.BeanstalkClientFactory;
import com.dinstone.beanstalkc.Configuration;
import com.dinstone.beanstalkc.Job;
import com.dinstone.beanstalkc.JobConsumer;

import java.util.Objects;

/**
 * @author zhoujie
 * Created on 2018-07-14 12:07
 */
public class BeanstalkConsumerRelease {
    public static void main(String[] args) {
        Configuration config = new Configuration();
        config.setServiceHost("127.0.0.1");
        config.setServicePort(11300);
        BeanstalkClientFactory factory = new BeanstalkClientFactory(config);
        JobConsumer consumer = factory.createJobConsumer("beanstalkd-demo");
        while (true) {
            Job job = consumer.reserveJob(3);
            if (Objects.isNull(job)) {
                continue;
            }
            System.out.println(job.getId());
            System.out.println(new String(job.getData()));
            consumer.releaseJob(job.getId(), 99, 5);
        }
    }
}
